home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_11.lha / 6_11 / 6_11_c2.c < prev    next >
Text File  |  1993-08-08  |  912b  |  47 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. *
  6.    create an arbint from a (unsigned) long
  7. /
  8. include <arbint.h>
  9.  
  10. onst arbperlong = sizeof(long) / sizeof(ARB_type);
  11.  
  12. rbint::arbint(long n)        // arbint x = 36L;
  13.  
  14.    // allocate data area
  15.    p = new arep;
  16.    p->refcnt = 1;
  17.    p->length = arbperlong;
  18.    p->value = new ARB_type[arbperlong];
  19.    
  20.    // assign the new value
  21.    for (int i = arbperlong - 1; i >= 0; i--)
  22.        {
  23. p->value[i] = n % ARB_base;
  24. n /= ARB_base;
  25. }
  26.  
  27.  
  28. rbint::arbint(unsigned long n)        // arbint x = 3UL;
  29.  
  30.    int nlen = arbperlong;
  31.    if ((long) n < 0)
  32. nlen++;
  33.  
  34.    // allocate data area
  35.    p = new arep;
  36.    p->refcnt = 1;
  37.    p->length = nlen;
  38.    p->value = new ARB_type[nlen];
  39.  
  40.    // assign the new value
  41.    for (int i = nlen - 1; i >= 0; i--)
  42.        {
  43. p->value[i] = n % ARB_base;
  44. n /= ARB_base;
  45. }
  46.  
  47.